﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// PaperReadAuth业务逻辑的简要说明。
    /// </summary>
    public class PaperReadAuth
    {
        /// <summary>
        /// 组织机构DAL
        /// </summary>
        private readonly DAL.PaperReadAuth dal = new DAL.PaperReadAuth();
        /// <summary>
        /// 构造函数
        /// </summary>
        public PaperReadAuth()
        { }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="strWhere">查询条件</param>
        /// <returns>DataTableToList表</returns>
        public List<Model.PaperReadAuth> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }


        /// <summary>
        /// 删除部门权限数据
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="fPaperId">编号</param>
        /// <param name="fSourceNo">操作人员</param>
        /// <param name="fPronoun">部门，个人，全部</param>
        /// <param name="fProp">类型</param>
        /// <param name="fEntityNo">公司编号</param>
        public void DeleteDept(decimal fPaperId, string fSourceNo, string fPronoun, string fProp, string fEntityNo)
        {

            dal.DeleteDept(fPaperId, fSourceNo, fPronoun, fProp, fEntityNo);
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// </summary>
        /// <param name="dt">DataTable表</param>
        /// <returns>DataTableToList集合</returns>
        public List<Model.PaperReadAuth> DataTableToList(DataTable dt)
        {
            List<Model.PaperReadAuth> modelList = new List<Model.PaperReadAuth>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PaperReadAuth model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PaperReadAuth();
                    if (dt.Rows[n]["FPaperId"] != null && dt.Rows[n]["FPaperId"].ToString() != "")
                    {
                        model.FPaperId = decimal.Parse(dt.Rows[n]["FPaperId"].ToString());
                    }
                    if (dt.Rows[n]["FSourceNo"] != null && dt.Rows[n]["FSourceNo"].ToString() != "")
                    {
                        model.FSourceNo = dt.Rows[n]["FSourceNo"].ToString();
                    }
                    if (dt.Rows[n]["FProp"] != null && dt.Rows[n]["FProp"].ToString() != "")
                    {
                        model.FProp = dt.Rows[n]["FProp"].ToString();
                    }
                    if (dt.Rows[n]["FPronoun"] != null && dt.Rows[n]["FPronoun"].ToString() != "")
                    {
                        model.FPronoun = dt.Rows[n]["FPronoun"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }



        /// <summary>
        /// 获取权限数据
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="paperID">题目编号</param>
        /// <returns>List集合</returns>
        public List<Model.PaperReadAuth> GetListAuth(decimal paperID)
        {
            DataSet ds = dal.GetListAuth(paperID);
            List<Model.PaperReadAuth> modelList = new List<Model.PaperReadAuth>();
            DataTable dt = ds.Tables[0];
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PaperReadAuth model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PaperReadAuth();
                    if (dt.Rows[n]["FPaperId"] != null && dt.Rows[n]["FPaperId"].ToString() != "")
                    {
                        model.FPaperId = decimal.Parse(dt.Rows[n]["FPaperId"].ToString());
                    }
                    if (dt.Rows[n]["FSourceNo"] != null && dt.Rows[n]["FSourceNo"].ToString() != "")
                    {
                        model.FSourceNo = dt.Rows[n]["FSourceNo"].ToString();
                    }
                    if (dt.Rows[n]["FProp"] != null && dt.Rows[n]["FProp"].ToString() != "")
                    {
                        model.FProp = dt.Rows[n]["FProp"].ToString();
                    }
                    if (dt.Rows[n]["FPronoun"] != null && dt.Rows[n]["FPronoun"].ToString() != "")
                    {
                        model.FPronoun = dt.Rows[n]["FPronoun"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    model.Allname = dt.Rows[n]["allname"].ToString();
                    model.Propname = dt.Rows[n]["propName"].ToString();
                    modelList.Add(model);
                }
            }


            return modelList;
        }

    }
}
